package org.epam.szhuk.greenway.util;

import java.io.IOException;

import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.RingtoneManager;
import android.net.Uri;

public final class AlarmUtil {
	public static void playSound(Context context) throws IllegalArgumentException, SecurityException, IllegalStateException,
		IOException {
		Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
		MediaPlayer mMediaPlayer = new MediaPlayer();
		mMediaPlayer.setDataSource(context, soundUri);
		final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
		if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
		    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
		    mMediaPlayer.setLooping(false);
		    mMediaPlayer.prepare();
		    mMediaPlayer.start();
		}
		else if (audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION) != 0) {
		    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
		    mMediaPlayer.setLooping(false);
		    mMediaPlayer.prepare();
		    mMediaPlayer.start();
		}
		}
}
